package com.itheima;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.junit.jupiter.api.Test;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author: Sch
 * @Date: 2025/07/16 9:57
 * @Description:
 */
public class test {

    @Test
    public void testGenJwt(){
        Map<String,Object> claims = new HashMap<>();
        claims.put("id",10);
        claims.put("username","itheima");

        String jwt = Jwts.builder().signWith(SignatureAlgorithm.HS256,"aXRjYXN0")
                .addClaims(claims)
                .setExpiration(new Date(System.currentTimeMillis()+60*1000))
                .compact();

        System.out.println(jwt);
    }

    @Test
    public void testParseJwt() {
        Claims claims = Jwts.parser().setSigningKey("aXRjYXN0")
                .parseClaimsJws("eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MTAsInVzZXJuYW1lIjoiaXRoZWltYSIsImV4cCI6MTc1MjY3NDY2MX0.3RT3-iWaM_9yrdRMTFVitQESEN6v5RsAox65Az4ssvU")
                .getBody();
        System.out.println(claims);
    }
    //{id=10, username=itheima, exp=1752674661}
}
